<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流水</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../bangnuo/admin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/modules/laydate/default/laydate.css" media="all">
    <script src="../../../bangnuo/admin/layui/layui.all.js"></script>
    <script src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
    <script src="../../../bangnuo/admin/layui/lay/modules/laypage.js"></script>
    <script src="../../../bangnuo/admin/layui/layui.js"></script>
</head>
<script>
    $(document).ready(function() {
        $.ajax({
            type: 'GET',
            url: '',
            dataType: "JSON",
            success: function (data) {
                if (data.success == true) {
                    console.log("显示");
                    console.log(data.data);
                    $(".LAY-agent-list").append(data.data);
                    $(".LAY-agent-list-box").show();
                } else {
                    console.log("隐藏");
                    $(".LAY-agent-list-box").hide();
                }
            }
        });
    });
</script>
<body>
<div class="layui-fluid">
    <div style="padding: 15px; display: none;" class="LAY-agent-list-box">
        <blockquote class="layui-elem-quote">
            <div class="LAY-agent-list">
            </div>
        </blockquote>
        <div>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">订单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="outTradeNo" placeholder="请输入" autocomplete="off" class="layui-input">
                        <input type="hidden" name="id" placeholder="" autocomplete="off" class="layui-input">

                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">流水号</label>
                    <div class="layui-input-block">
                        <input type="text" name="serialNumber" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="status">
                            <option value="">全部</option>
                            <option value="0">待支付</option>
                            <option value="1">支付成功</option>
                            <option value="2">支付失败</option>
                            <option value="3">已退款</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">支付方式</label>
                    <div class="layui-input-block">
                        <select name="payType">
                            <option value="">全部</option>
                            <option value="F">刷脸</option>
                            <option value="C">扫码</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">支付类型</label>
                    <div class="layui-input-block">
                        <select name="payWay">
                            <option value="">全部</option>
                            <option value="0">支付宝</option>
                            <option value="1">微信</option>
                        </select>
                    </div>
                </div>
                </br>

                <div class="layui-inline">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="startTime"  id="startTime"
                               placeholder="开始时间">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline">
                        <input type="text"  name="endTime" value="" id="endTime" placeholder="结束时间"
                               class="layui-input">
                    </div>
                </div>
                <a href="#" onclick="today()">当日</a>&nbsp;
                <a href="#" onclick="yesterday()">昨日</a>&nbsp;
                <a href="#" onclick="san_days()">前3日</a>&nbsp;
                <!--<a href="#" onclick="qi_days()">前7日</a>&nbsp;-->
                <a href="#" onclick="this_month()">当月</a>&nbsp;
                <a href="#" onclick="last_month()">上月</a>
                </br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <div class="layui-inline">
                    <button class="layui-btn layui-admin-btn-useradmin" lay-submit
                            lay-filter="LAY-user-front-search">查询
                        <!--<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
                    </button>
                    <button class="layui-btn layui-admin-btn-useradmin" lay-submit
                            lay-filter="LAY-user-front-search-today">当日订单
                        <!--<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
                    </button>
                    <button class="layui-btn layui-admin-btn-useradmin" lay-submit
                            lay-filter="LAY-user-front-search-yesterday">昨日订单
                        <!--<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
                    </button>
                    <button class="layui-btn layui-admin-btn-useradmin" lay-submit
                            lay-filter="LAY-user-front-search-month">当月订单
                        <!--<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
                    </button>

                </div>
                <p>
                    <button class="layui-btn layui-btn-normal" id="select" lay-submit
                            lay-filter="select">
                        有效汇总
                    </button>
                    <span id="text"></span>
                </p>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="admin-demo" lay-filter="admin-demo"></table>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={ { d.avatar }}>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>详情</a>
            </script>
        </div>
    </div>
</div>
</body>
<script src="../../../bangnuo/admin/layui/layui.js"></script>
<script type="text/html" id="tpl_agentState">
    {{# if(d.status == 0){ }}
    <b style="color: blue;">待支付</b>
    {{# }  }}

    {{# if(d.status == 1){ }}
    <b style="color: blue;">支付成功</b>
    {{# }  }}

    {{# if(d.status == 2){ }}
    <b style="color: blue;">支付失败</b>
    {{# }  }}

    {{# if(d.status == 3){ }}
    <b style="color: blue;">已退款</b>
    {{# }  }}
</script>
<script type="text/html" id="tpl_pay_type">
    {{# if(d.payType == 'F'){ }}
    <b style="color: blue;">刷脸</b>
    {{# }  }}

    {{# if(d.payType == 'C'){ }}
    <b style="color: blue;">扫码</b>
    {{# }  }}
</script>
<script type="text/html" id="tpl_pay_way">
    {{# if(d.payWay == 0){ }}
    <b style="color: blue;">支付宝</b>
    {{# }  }}

    {{# if(d.payWay == 1){ }}
    <b style="color: blue;">微信</b>
    {{# }  }}
</script>
<script type="text/html" id="actualPayment">
    {{d.actualPayment/100 }}
</script>
<script type="text/javascript">
    $(document).ready(function () {
        layui.use('laydate', function () {
            var laydates = layui.laydate;
            laydates.render({elem: '#startTime', type: 'datetime', format: 'yyyy-MM-dd HH:mm:ss'})
            laydates.render({elem: '#endTime', type: 'datetime', format: 'yyyy-MM-dd HH:mm:ss'})
        });
    });

</script>
<script type="text/javascript">

</script>
<script type="text/javascript">

    function today() {//今天
        var date = new Date();
        var dd = date.getFullYear();
        var mm = date.getMonth() + 1;
        var aa = date.getDate();

        //今天的时间
        var startToday = dd + "-" + mm + "-" + aa + " 00:00:00";//今天凌晨
        var endToday = dd + "-" + mm + "-" + aa + " 23:59:59";//今天晚上12点
        $("#startTime").val(startToday);
        $("#endTime").val(endToday);

    };
</script>
<script type="text/javascript">
    function yesterday() {
        var date = new Date();
        var dd = date.getFullYear();
        var mm = date.getMonth() + 1;
        var aa = date.getDate();
//昨天的时间
        var startYesterday = dd + "-" + mm + "-" + (aa - 1) + " 00:00:00";//昨天凌晨
        var endYesterday = dd + "-" + mm + "-" + (aa - 1) + " 23:59:59";//今天凌晨
        $("#startTime").val(startYesterday)
        $("#endTime").val(endYesterday)
    }
</script>
<script type="text/javascript">
    function san_days() {
        var date = new Date();
        var dd = date.getFullYear();
        var mm = date.getMonth() + 1;
        var aa = date.getDate();
        // 前3天时间
        var start3_days = dd + "-" + mm + "-" + (aa - 3) + " 00:00:00";//前7天凌晨
        var end3_days = dd + "-" + mm + "-" + (aa - 1) + " 23:59:59";//昨天凌晨

        $("#startTime").val(start3_days);
        $("#endTime").val(end3_days);
    }
</script>
<script type="text/javascript">
    function qi_days() {
        var date = new Date();
        var dd = date.getFullYear();
        var mm = date.getMonth() + 1;
        var aa = date.getDate();
        //前7天时间
        var start7_days = dd + "-" + mm + "-" + (aa - 7) + " 00:00:00";//前7天凌晨
        var end7_days = dd + "-" + mm + "-" + (aa - 1) + " 23:59:59";//昨天凌晨

        $("#startTime").val(start7_days);
        $("#endTime").val(end7_days);
    }
</script>
<script type="text/javascript">
    function this_month() {
        var date = new Date();
        var dd = date.getFullYear();
        var mm = date.getMonth() + 1;
        var aa = date.getDate();
        var cc=aa-aa+1;//每月的第一天

        var startMonth = dd + "-" + mm + "-" + cc+" 00:00:00";//当月第一天
        var endMonth = dd + "-" + mm + "-" + aa + " 23:59:59";//当月今天
        $("#endTime").val(endMonth)
        // alert(startMonth)
        $("#startTime").val(startMonth);
        // alert(dd + "-" + mm +"-"+ (aa - aa + 1) + " 00:00:00")
    }
</script>
<script type="text/javascript">
    function last_month() {
        var date = new Date();
        var dd = date.getFullYear();
        var mm = date.getMonth();
        if (mm == 0) {
            dd = dd - 1;
            mm = 12;
        }
        /*if (mm < 10) {
            mm = '0' + mm;
        }*/
        var myDate = new Date(dd, mm, 0);

        var startLastMonth = dd + "-" + (mm) + "-" + "01 00:00:00";//上个月第一天凌晨
        var endLatMonth = dd + '-' + (mm) + '-' + myDate.getDate() + ' 23:59:00';//上个月最后一天

        $("#startTime").val(startLastMonth);
        $("#endTime").val(endLatMonth);
    }


</script>
<script>
    layui.use(['form', 'upload', 'layer'], function () {

        var form = layui.form;
        form.on('submit(select)', function (data) {

            var order = {
                "outTradeNo": data.field.outTradeNo,
                "serialNumber": data.field.serialNumber,
                "status": data.field.status,
                "payType": data.field.payType,
                "payWay": data.field.payWay,
                "startTime": data.field.startTime,
                "endTime": data.field.endTime,
                "id": data.field.id
            }
            var realConsume = 0;
            var realMoney = 0;
            var realDiscounts = 0;
            var total = 0;
            var actualTui = 0;
            $.ajax({
                type: "post",
                url: '/order/listSelect',
                data: JSON.stringify(order),
                // dataType: 'json',
                contentType: "application/json;charset=UTF-8",
                // dataType:"html",
                success: function (data) {
                    realConsume = data.queryResult.list[0].realConsume;
                    realMoney = data.queryResult.list[0].realMoney;
                    realDiscounts = data.queryResult.list[0].realDiscounts;
                    total = data.queryResult.list[0].total;
                    actualTui = data.queryResult.list[0].actualTui;
                    document.getElementById("text").innerText = "总计：支付成功订单" + total + "条，实收金额：" + realMoney + "元，优惠金额：" + realDiscounts + "元，当前时间段退款金额：" + actualTui + "元";
                }
            })
            return false;
        })
        ;
        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        /*$.ajax({
            url: '/adminEntity/admin',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.data;
                for (var x in resultData) {
                    htmls += '<option value = "' + resultData[x].value + '">' + resultData[x].name + '</option>';
                }
                $("#merchantsIdAdminId").html(htmls);
                form.render('select');
                //重新渲染 固定写法
            }
        })*/
    })
    ;
</script>
<script>

    layui.use(['table', 'form'], function () {
        var table = layui.table,
            form = layui.form;

        form.on('submit(LAY-user-front-search)', function (data) {
            var order = {
                "outTradeNo": data.field.outTradeNo,
                "serialNumber": data.field.serialNumber,
                "status": data.field.status,
                "payType": data.field.payType,
                "payWay": data.field.payWay,
                "startTime": data.field.startTime,
                "endTime": data.field.endTime,
                "id": data.field.id
            }
            table.reload('admin-overloading', {
                url: '/order/list',
                where: order,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        //当日订单
        form.on('submit(LAY-user-front-search-today)', function (data) {
            var date = new Date();
            var dd = date.getFullYear();
            var mm = date.getMonth() + 1;
            var aa = date.getDate();
            //今天的时间
            var startToday = dd + "-" + mm + "-" + aa + " 00:00:00";//今天凌晨
            var endToday = dd + "-" + mm + "-" + aa + " 23:59:59";//今天晚上12点
            $("#startTime").val(startToday);
            $("#endTime").val(endToday);
            var order = {
                "outTradeNo": data.field.outTradeNo,
                "serialNumber": data.field.serialNumber,
                "status": data.field.status,
                "payType": data.field.payType,
                "payWay": data.field.payWay,
                "startTime": data.field.startTime,
                "endTime": data.field.endTime,
                "id": data.field.id
            }
            table.reload('admin-overloading', {
                url: '/order/list',
                where: order,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        //昨日订单
        form.on('submit(LAY-user-front-search-yesterday)', function (data) {
            var date = new Date();
            var dd = date.getFullYear();
            var mm = date.getMonth() + 1;
            var aa = date.getDate();
            //昨天的时间
            var startYesterday = dd + "-" + mm + "-" + (aa - 1) + " 00:00:00";//昨天凌晨
            var endYesterday = dd + "-" + mm + "-" + (aa - 1) + " 23:59:59";//今天凌晨
            $("#startTime").val(startYesterday)
            $("#endTime").val(endYesterday)
            var order = {
                "outTradeNo": data.field.outTradeNo,
                "serialNumber": data.field.serialNumber,
                "status": data.field.status,
                "payType": data.field.payType,
                "payWay": data.field.payWay,
                "startTime": data.field.startTime,
                "endTime": data.field.endTime,
                "id": data.field.id
            }
            table.reload('admin-overloading', {
                url: '/order/list',
                where: order,
                page: {
                    curr: 1
                }
            });
            return false;
        });
//当月订单
        form.on('submit(LAY-user-front-search-month)', function (data) {
            var date = new Date();
            var dd = date.getFullYear();
            var mm = date.getMonth() + 1;
            var aa = date.getDate();
            var cc=aa-aa+1;//每月的第一天

            var startMonth = dd + "-" + mm + "-" + cc+" 00:00:00";//当月第一天
            var endMonth = dd + "-" + mm + "-" + aa + " 23:59:59";//当月今天
            $("#endTime").val(endMonth)
            // alert(startMonth)
            $("#startTime").val(startMonth);
            // alert(startMonth)
            var order = {
                "outTradeNo": data.field.outTradeNo,
                "serialNumber": data.field.serialNumber,
                "status": data.field.status,
                "payType": data.field.payType,
                "payWay": data.field.payWay,
                "startTime": data.field.startTime,
                "endTime": data.field.endTime,
                "id": data.field.id
            }
            table.reload('admin-overloading', {
                url: '/order/list',
                where: order,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //第一个实例
        table.render({
            elem: '#admin-demo',
            method: "POST",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            url: '/order/list', //数据接口
            contentType: "application/json;charset=UTF-8",
            parseData: function (res) { //res 即为原始返回的数据
                console.log("res执行", res);
                return {
                    "code": 0, //解析接口状态
                    "msg": "", //解析提示文本
                    "count": res.queryResult.total, //解析数据长度
                    "data": res.queryResult.list//解析数据列表
                };
            },
            page: true, //开启分页
            limit: 5,
            id: "admin-overloading",
            limits: [5, 10, 20, 50, 100],
            cols: [
                [ //表头
                    {
                        field: 'id',
                        title: 'ID',
                        width: 80,
                        sort: true,
                        fixed: 'left'
                    }, {
                    field: 'outTradeNo',
                    title: '订单号',
                    width: 100
                }, {
                    field: 'serialNumber',
                    title: '流水号',
                    width: 120
                }, {
                    field: 'actualPayment',
                    title: '实收金额',
                    width: 120,
                    templet: "#actualPayment",
                    sort: true
                }, /*{
                    field: 'note',
                    title: '备注',
                    width: 100
                },*/ {
                    field: 'status',
                    title: '状态',
                    width: 100,
                    templet: "#tpl_agentState"
                },{
                    field: 'shopId',
                    title: '所属门店',
                    width: 100,
                }, {
                    field: 'sn',
                    title: '机具名称',
                    width: 100,
                }, {
                    field: 'payType',
                    title: '支付类型',
                    width: 100,
                    templet: "#tpl_pay_type"
                }, {
                    field: 'payWay',
                    title: '支付方式',
                    width: 100,
                    templet: "#tpl_pay_way"
                }, {
                    field: 'createTime',
                    title: '创建时间',
                    width: 150,
                    templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'
                },
                    {
                        title: '操作',
                        fixed: 'right',
                        align: 'center',
                        toolbar: '#table-useradmin-webuser'
                    }
                ]
            ]
        });
        table.on('tool(admin-demo)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'del') { //删除
                layer.confirm('真的删除行么', function (index) {
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        type: "GET",
                        // url: "/adminEntity/delAdmin/" + data.adminUuid,
                        url: "/terminalEntity/delTerminal/" + data.terminalUuid,
                        async: true,
                        success: function (data) {
                            if (data.success == true) {
                                layer.msg("删除成功");
                            } else {
                                layer.msg("删除失败");
                            }
                        }
                    });
                });
            } else if (layEvent === 'edit') { //编辑
                //do something
                //同步更新缓存对应的值
                layer.open({
                    type: 2,
                    title: '账单详情',
                    area: ['500px', '600px'],
                    // content: 'users/edit-shop.html?id=' + data.adminUuid //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    content: 'operation/edit-order.html?id=' + data.id//这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
                obj.update({
                    username: '123',
                    title: 'xxx'
                });
            } else if (layEvent === 'LAYTABLE_TIPS') {
                layer.alert('Hi，头部工具栏扩展的右侧图标。');
            }
        });
    });
</script>

</html>